/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package vista;

import clases.Categoria;
import com.alee.laf.button.WebButton;
import com.alee.laf.label.WebLabel;
import com.alee.laf.panel.WebPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;

/**
 *
 * @author Edder
 */
public class ItmCategoria extends WebPanel implements ActionListener{
    private final Categoria categoria;
    private final FrmCategorias parent;
    private WebLabel lblCategoria;
    private WebButton btnEditar;
    
    public ItmCategoria(FrmCategorias parent, Categoria categoria){
        this.parent = parent;
        this.categoria = categoria;
        initComponents();
    }
    
    /**
     * Inicializa los componentes del panel
     */
    private void initComponents(){
        setBackground(Color.white);
        setMaximumSize(new Dimension(600, 35));
        this.lblCategoria = new WebLabel();
        this.lblCategoria.setText(this.categoria.getNombre());
        this.btnEditar = new WebButton(new ImageIcon(getClass().getResource("/resources/img/cog.png")));
        setLayout(new BorderLayout());
        this.add(this.lblCategoria, BorderLayout.CENTER);
        this.add(new WebPanel(){
            {
                setBackground(Color.white);
                setLayout(new FlowLayout(FlowLayout.RIGHT));
                this.add(btnEditar);
            }
        }, BorderLayout.EAST);
        this.btnEditar.addActionListener(this);
    }

    /**
     * Abre Dialog para editar categoria,
     * luego actualiza la información a mostrar
     */
    private void editarCategoria(){
        FrmCategoria fc = new FrmCategoria(null, true, this.categoria);
        fc.setVisible(true);
        this.parent.llenarCategorias();
    }
    
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource() == this.btnEditar){
            editarCategoria();
        }
    }
}
